<?php
/**
 * @ Fmash Top System
 * @ version: 3.0
 * @ author: i.coffee.smile@mail.com
 * @ date:2011-1-27
 * @ file:function_math.php $7
 */

/**
 *	@ 注意：本页代码包含重要的加密函数和解密函数，如果
 *  @ 本页代码泄露，那么可以直接编写出作弊的脚本！
 **/

//加密两个ID变成一个URL
function enid($id1,$id2)
{
	$en_id1_1 = $id1 * 123456 + 1314520;
	$en_id2_1 = $id2 * 123456 + 1314520;
	$en_id_2 = md5(time()*131*$id1).$en_id1_1.'.'.$en_id2_1.time().sha1($id1).sha1(time()*$id2);
	$en_id_3 = base64_encode($en_id_2);
	return $en_id_3;
}

//将加密的URL还原为2个ID和时间
function deid($str)
{
	$de_id_1 = base64_decode($str);
	$de_id_2 = substr($de_id_1,0,-80);
	$detime = substr($de_id_2,-10);
	$de_id_3 = substr($de_id_2,32,-10);
	$deid = explode('.',$de_id_3);
	$deid1 = ($deid[0] - 1314520)/123456;
	$deid2 = ($deid[1] - 1314520)/123456;
	$deid = array('id1'=>"$deid1",'id2'=>"$deid2",'detime'=>"$detime");
	return $deid;
}

//首页查看资料的时候加密
function en_see($sid)
{
	$sid = $sid * 111;
	$sid_2 = base64_encode($sid.time());
	$sid_3 = base64_encode($sid_2.sha1(time()*2));
	return $sid_3;
}

//查看资料页面的时候解密
function de_see($str)
{
	$de = base64_decode($str);
	$de2 = substr($de,0,-40);
	$de3 = base64_decode($de2);
	$detime = substr($de3,-10);
	$de4 = substr($de3,0,-10);
	$deid = $de4 / 111;
	if(time() - $detime > 10)
	{
		header("location:show.php?id=$deid");
	}
	return $deid;
}